<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var maxDepth = function (root) {
            var max = 0
            function fn(root, count) {
                if (root === null) return

                count++
                max = Math.max(count, max)

                if (root.left !== null) {
                    fn(root.left, count)
                }
                if (root.right !== null) {
                    fn(root.right, count)
                }
            }
            fn(root, 0)
            return max
        };

        {
            var maxDepth = function(root) {
                if (root === null) return 0
                return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1
            }
        }
    </script>
</body>

</html>